<?php
/*
    "NuSOAP and WSDL"
    http://www.nonplus.net/geek/000752.php

    Copyright 2003, Stepan Riha, All right reserved.

    You're free to make derivative and commercial use of this code
    without attribution.

    Version 2.0 - Oct 29, 2003
    Fixed problems with unquoted string constants.

*/
require_once ('config/cfg.php');

//apache htaccess - www authentication
if ( ( !isset( $PHP_AUTH_USER )) || (!isset($PHP_AUTH_PW))
     || ( $PHP_AUTH_USER != $htaccessUser ) || ( $PHP_AUTH_PW != $htaccessPassword ) ) {
    header( 'WWW-Authenticate: Basic realm="Private"' );
    header( 'HTTP/1.0 401 Unauthorized' );
    echo "This folder is protected ";
    exit;
}

//Init SOAP server
$NAMESPACE = 'urn:Callware';
$server = new soap_server;
$server->debug_flag=false; 
$server->configureWSDL('Callware', $NAMESPACE);
$server->wsdl->schemaTargetNamespace = $NAMESPACE;

//Include webservice's functions
$base_folder=dirname(__FILE__) . "/modules";
if($handle=opendir($base_folder)){
  while(false !== ($file = readdir($handle))){
    if(($file==".")||($file=="..")||(trim($file)=="")) continue;
    if((is_dir($base_folder."/".$file))                       &&
       (is_file($base_folder."/".$file."/functions/methods.php"))       &&
       (is_file($base_folder."/".$file."/functions/declarations.php"))  &&
       (is_file($base_folder."/".$file."/functions/registrations.php")) ){
    	// ==== METHOD IMPLEMENTATION ====
      require_once $base_folder."/".$file."/functions/methods.php";
			// ==== WSDL TYPES DECLARATION ====
      require_once $base_folder."/".$file."/functions/declarations.php";
      // ==== WSDL METHODS REGISTRATION ====
      require_once $base_folder."/".$file."/functions/registrations.php";
    }
  }
  closedir($handle);
}

//Process Request
$HTTP_RAW_POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
$server->service($HTTP_RAW_POST_DATA);
exit();
?>